import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-07-06
 * Time: 19:16
 */
public class Test {
    public static void main1(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        //使用for-each遍历
        for (int x:list) {
            System.out.print(x + " ");
        }
        System.out.println();
        //使用迭代器遍历 -- 正向遍历
        ListIterator<Integer> it = list.listIterator();
            while(it.hasNext()) {
                System.out.print(it.next() + " ");
            }
        System.out.println();
        //使用迭代器遍历 -- 反向遍历
        ListIterator<Integer> itr = list.listIterator(list.size());
        while(itr.hasPrevious()) {
            System.out.print(itr.previous() + " ");
        }
    }
    public static void main(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        System.out.println("===头插法===");
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(5);
        System.out.println("===尾插法===");
        myLinkedList.addLast(1);
        myLinkedList.addLast(2);
        myLinkedList.display();
        System.out.println("===指定插法===");
        myLinkedList.addIndex(0,99);
        myLinkedList.addIndex(3,99);
        myLinkedList.addIndex(9,99);
        myLinkedList.display();
        System.out.println("===删除第一个data===");
        myLinkedList.remove(99);
        myLinkedList.display();
        System.out.println("===删除所有data===");
        myLinkedList.removeAllKey(99);
        myLinkedList.display();
        System.out.println(myLinkedList.size());
        System.out.println("===清除链表===");
        myLinkedList.clear();
        myLinkedList.display();

    }
}
